package com.bird.thread.base.thread;

import java.util.concurrent.TimeUnit;

/**
 * @author sijunqiang
 * @data 2021/7/2 22:02
 * @description: 目的：使用synchronized 替换join
 */
public class JoinPrinciple {


    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    // 让子线程休眠
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + " 线程执行完毕！");
            }
        });
        thread.start();
        System.out.println("开始等待子线程运行完毕...");
        // 主线程等待 让子线程执行完毕后 然后唤醒 让主线程在再执行。
        thread.join();
    }
}
